package com.bestom.videoplay.activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.bestom.videoplay.MediaApplication;
import com.bestom.videoplay.R;


public class SettingsActivity extends AppCompatActivity {

    private static final String TAG = "SettingsActivity";

    private Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        mContext = this;
        textName = findViewById(R.id.text_name);
        bluetooth_bt= findViewById(R.id.bluetooth_bt);
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle(getString(R.string.setting));

        setSupportActionBar(toolbar);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    private TextView textName;
    private TextView bluetooth_bt;

    @Override
    protected void onResume() {
        super.onResume();
        /*if (MediaApplication.getApplication().getBluetoothName() == null){
            setText(false);
        }else {
            setText(true);
        }*/


    }

    public void setText(boolean connect) {
        if(connect){
            bluetooth_bt.setText(R.string.disconnect);
//            textName.setText(MediaApplication.getApplication().getBluetoothName());
        }else {
            bluetooth_bt.setText(R.string.connect);
            textName.setText(R.string.unconnected);
        }
    }


    /**
     * 断开连接
     * void at layout
     */
    public void disconnect(){

        BlueToothActivity.getInstance().disconnect();
        setText(false);

    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {

        switch (item.getItemId()){
            case android.R.id.home:
                onBackPressed();
                break;
            default:
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    /**
     * 开始扫描 10秒后自动停止
     * */

    @Override
    protected void onDestroy() {
        super.onDestroy();


    }

    public void setBlueTooth(View view) {
        if (bluetooth_bt.getText().equals("设置连接")){
            Intent intent = new Intent(mContext,BlueToothActivity.class);
            // 意图返回连接成功的设备名
            startActivity(intent);
        }else {
            disconnect();
        }

    }
}
